package com.woniuxy.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.Poetry;
import com.woniuxy.service.PoetryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/crud")
public class PoetryController {

    private PoetryService poetryService;

    @Autowired
    public void setPoetryService(PoetryService poetryService) {
        this.poetryService = poetryService;
    }

    @PostMapping("/find")
    @ResponseBody
    public PageInfo<Poetry> findOnePage(int currentPage, Poetry poetry){
        PageInfo<Poetry> info = poetryService.findOnePage(currentPage, poetry);
        return info;
    }

    @GetMapping("/delet")
    @ResponseBody
    public String deleteByIds(Integer[] ids){
        boolean flag = poetryService.deleteByIds(ids);
        return flag?"ok":"no";
    }

    @PostMapping("/updata")
    @ResponseBody
    public String updata(@RequestBody Poetry poetry){
        boolean flag = poetryService.updata(poetry);
        return flag?"ok":"no";
    }

    @RequestMapping("/add")
    @ResponseBody
    public String add(@RequestBody Poetry poetry){
        boolean flag = poetryService.add(poetry);
        return flag?"ok":"no";
    }
}
